#include<algorithm>
class Solution {
public:
    int integerReplacement(int n) {
        if (n == 1) return 0;
        if (n == INT_MAX) return 32;
        int res = 0;
        if (n % 2 == 0)
            res= integerReplacement(n>>1);
        else
            res=std::min(integerReplacement(n + 1), integerReplacement(n - 1));
        return res + 1;
    }
};